package com.lagou;

import com.lagou.monitor.TPMonitorThread;
import com.lagou.service.HelloService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ConsumerApplication {
    public static void main(String[] args) throws  Exception{
        ClassPathXmlApplicationContext applicationContext  = new ClassPathXmlApplicationContext("classpath:dubbo-comsumer.xml");
        //applicationContext.start();
        ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor(1);
        // 每隔 5 秒监控一次 TP90和 TP99
        scheduled.scheduleAtFixedRate(new TPMonitorThread(), 10, 5, TimeUnit.SECONDS);
        ExecutorService service =  Executors.newFixedThreadPool(4);
        HelloService  helloService  = applicationContext.getBean("helloService",HelloService.class);
        for(int i=0; i < 2000; i++) {

            for(int j=0; j < 1000; i++) {
                service.submit(new Runnable() {
                    @Override
                    public void run() {
                        String result = helloService.sayHelloA("world");
                        String resultB = helloService.sayHelloB("world");
                        String resultC = helloService.sayHelloC("world");
                    }
                });
            }
            Thread.sleep(TimeUnit.SECONDS.toMillis(RandomUtils.nextInt(10, 50)));
        }


        System.in.read();

    }
}
